package com.heba.utils;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.heba.greenmulu.R;

/**
 * Glide图片加载
 * Created by jason on 2019/6/13.
 */
public class GlideUtil {

    /**
     * 加载图片
     *
     * @param context
     * @param url
     * @param imageView
     * @param options
     */
    public static void load(Context context,
                            String url,
                            ImageView imageView,
                            RequestOptions options) {

        Glide.with(context)
                .load(url)
                .apply(options)
                .into(imageView);
    }

    /**
     * 加载图片
     *
     * @param context
     * @param url
     * @param imageView
     */
    public static void load(Context context,
                            String url,
                            ImageView imageView) {

        Glide.with(context)
                .load(url)
                .into(imageView);
    }

    /**
     * 加载图片 指定默认的占位图
     *
     * @param context
     * @param url
     * @param imageView
     */
    public static void loadImageWithDefaultPlaceHolder(Context context,
                                                       String url,
                                                       ImageView imageView) {
        RequestOptions options = new RequestOptions()
                .placeholder(R.drawable.btn_upload_image)
                .error(R.drawable.btn_upload_image);

        Glide.with(context)
                .load(url)
                .apply(options)
                .into(imageView);
    }

    /**
     * 加载图片
     *
     * @param context
     * @param url
     * @param imageView
     * @param drawableID 占位图
     */
    public static void loadImageWithPlaceHolderID(Context context,
                                                  String url,
                                                  ImageView imageView,
                                                  int drawableID) {
        RequestOptions options = new RequestOptions()
                .placeholder(drawableID);

        Glide.with(context)
                .load(url)
                .apply(options)
                .into(imageView);
    }

}
